package com.wangsd.web.service.account.imp;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wangsd.web.entity.account.Income;
import com.wangsd.web.mapper.account.IncomeMapper;
import com.wangsd.web.service.account.IncomeService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class IncomeServiceImp implements IncomeService {

    @Resource
    private IncomeMapper incomeMapper;

    /**
     * 存款
     * @param income 账目信息
     * @return 格式化信息
     */
    @Override
    public boolean save(Income income) {
        return incomeMapper.insert(income) > 0;
    }

    /**
     * 删除账单信息
     * @param incomeId 账单ID
     * @return 格式化信息
     */
    @Override
    public boolean delete(Integer incomeId) {
        return incomeMapper.deleteById(incomeId) > 0;
    }

    /**
     * 修改账单信息
     * @param income 账单实体
     * @return 格式化信息
     */
    @Override
    public boolean modify(Income income) {
        return incomeMapper.updateById(income) > 0;
    }

    /**
     *
     * @param incomeId id
     * @return 实体对象
     */
    @Override
    public Income getById(int incomeId) {
        return incomeMapper.selectById(incomeId);
    }

    /**
     * 获取最新十条记录
     * @return 格式化信息
     */
    @Override
    public List<Income> getTen(Integer userId, Page<Income> page) {
        QueryWrapper<Income> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);
        return incomeMapper.selectPage(page, queryWrapper).getRecords();
    }

    /**
     * 获取全部信息
     * @return 格式化信息
     */
    @Override
    public List<Income> getAll(Integer userId) {
        QueryWrapper<Income> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("userId", userId);
        return incomeMapper.selectList(queryWrapper);
    }
}
